
package urnoted;
import java.awt.*;
import java.util.ArrayList;
import javax.swing.*;

import urnoted.Controller;

public class KeyboardPanel extends JPanel {
    private static final int WIDTH = 500;
    private static final int HEIGHT = 300;
    private static final Font KEY_FONT = new Font("Arial Bold", Font.BOLD, 40);
    private Controller controller;
    private String[] names = {"C4", "D4", "E4", "F4", "G4", "A5", "B5", "C5",
            "D5", "E5", "F5", "G5"};
    private int n = names.length;  // the number of white keys
    private ArrayList<Key> keys;

    public KeyboardPanel(Controller controller, boolean showNames) {
        this.controller = controller;
        this.keys = new ArrayList<Key>();
        this.setPreferredSize(new Dimension(WIDTH, HEIGHT));
        
        this.setLayout(new GridLayout(1, n, 0, 0));
        for (int i = 0; i < n; i++) {
            Key key = new Key(controller, i, names[i]);
            keys.add(key);
            this.add(key);
        }
    }
    
    public void resetKeys()
    {
    	for(Key k : keys)
    	{
    		k.setKeyColor(Color.WHITE);
    		k.repaint();
    	}
    }
    
    public void setNewKey(Note n)
    {
    	for(int i = 0;i<keys.size();i++)
    	{
    		if(keys.get(i).getName().equals(n.name()))
    		{
    			keys.get(i).setKeyColor(Color.GREEN);
    		}
    		else
    		{
    			keys.get(i).setKeyColor(Color.WHITE);
    		}
    		keys.get(i).repaint();
    	}
    }
    
    public void highlightWrongKey(Note n)
    {
    	for(int i = 0;i<keys.size();i++)
    	{
    		if(keys.get(i).getName().equals(n.name()))
    		{
    			keys.get(i).setKeyColor(Color.RED);
    			keys.get(i).repaint();
    			keys.get(i).clearAfterMilli(1000);
    		}
    	}
    }
}
